#!/usr/bin/python
import os
import sys
import csv
from collections import defaultdict
reader = csv.reader(open("instances_map", "r"), delimiter=' ')
names = {}
for row in reader:
  names[row[0]] = row[1]

for instance in names.values():
  print instance
  ratios_file = csv.reader(open(instance+"/ratios.txt"), delimiter=';')
  hconstraints = defaultdict(list)
  lconstraints = defaultdict(list)
  rownum = 0;
  for row in ratios_file:
    if ( rownum != 0 ):
      n = row[0].split('/')
      p = int(n[1]);
      n = n[0];
      if ( row[1] == '1' ):
        hconstraints[n].append(p)
      else:
        lconstraints[n].append(p)
    rownum +=1;
  for key in hconstraints:
    hconstraints[key].sort()
  for key in lconstraints:
    lconstraints[key].sort()
  for key in hconstraints:
    sys.stdout.write(key+"/(")
    for p in hconstraints[key]:
      sys.stdout.write(","+str(p))
    sys.stdout.write(") ")
  print
  for key in lconstraints:
    sys.stdout.write(key+"/(")
    for p in lconstraints[key]:
      sys.stdout.write(","+str(p))
    sys.stdout.write(") ")
  print
